package club.xinghe.biz;

import club.xinghe.dao.StudentDao;
import club.xinghe.entity.Student;
import club.xinghe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明:对学生进行操作的业务
 *
 * @姚文斌
 * @create 2019-09-28 下午 6:22
 */
public class StudentBiz {
    SqlSession session= SqlSessionFactoryUtil.getSqlSession ();
    StudentDao studentDao =session.getMapper ( StudentDao.class  );
    //1.学生登录
    public Student studentLogin(Student student){
        return studentDao.studentLogin(student);
    }


    /*显示学生*/
    public List<Student> showUser(){
        return studentDao.showStudent ();
    }


    /*增加学生*/
    public boolean addStudent(Student student){
        boolean result=studentDao.addStudent ( student );
        session.commit ();
        return result;
    }

    /*修改学生*/

    public boolean updateStudent(Student student){
        boolean result=studentDao.updateStudent ( student );
        session.commit ();
        return result;
    }
    /*删除学生*/

    public boolean deleteStudent(int sId){
        boolean result=studentDao.deleteStudent ( sId );
        session.commit ();
        return result;
    }

    /*根据用户ID得到用户信息*/
    public Student getStudentById(int sId){
        return studentDao.getStudentById ( sId );

    }

    /*根据zid yid cid 查找学生信息*/
    public  List<Student> getStudentBykey(int yid, int zid, int cid,int gid){
        Map<String,Integer> map=new HashMap<> (  );
        map.put ( "yid",yid );
        map.put ( "zid",zid );
        map.put ( "cid",cid );
        map.put ( "gid",gid );
        return  studentDao.getStudentByKey ( map );
    }
    /*统计总行数*/
    public  int getCountStudent(){
        return studentDao.getCountStudent ();
    }
    /*分页*/
    public List<Student>selectStudentByMap(int currPage,int pageSize){
        int start=pageSize*(currPage-1);
        Map<String,Object> map=new HashMap<> (  );
        map.put ( "start",start );
        map.put ( "pageSize",pageSize );
        List<Student>studentList=studentDao.selectStudentByMap ( map );
        return studentList;
    }
    /*分页后的总页数*/
    public int countPages(int countPages,int pageSizes){
        return countPages%pageSizes==0?countPages/pageSizes:((countPages/pageSizes)+1);
    }
}
